import { createRouter,createWebHashHistory,createWebHistory } from "vue-router";

const router = createRouter({
    history: createWebHashHistory(import.meta.env.BASE_URL),
    routes: [
        {path:'/',redirect:'/login'},
        {path:'/manager',name:'manager',meta:{title:'首页'},component:()=>import('../views/Manager.vue'),children:[
            {path:'home',name:'home',meta:{title:"首页"},component:()=>import('../views/Home.vue')},
            {path:'data',name:'data',meta:{title:"数据展示"},component:()=>import('../views/Data.vue')},
            {path:'user',name:'user',meta:{title:"用户管理"},component:()=>import('../views/system/User.vue')},
            {path:'updatePassword',name:'updatePassword',meta:{title:"修改密码"},component:()=>import('../views/system/UpdatePassword.vue')},
            {path:'article',name:'article',meta:{title:"文章列表"},component:()=>import('../views/article/Article.vue')},
            {path:'org',name:'org',meta:{title:"机构管理"},component:()=>import('../views/system/Org.vue')},
        ]},
        {path:'/login',name:'Login',meta:{title:"登录"},component:()=>import('../views/Login.vue')},
        {path:'/test',name:'test',meta:{title:"测试页"},component:()=>import('../views/Test.vue')},
        {path:'/404',name:'notFound',meta:{title:"404找不到页面"},component:()=>import('../views/404.vue')},
        {path:'/:patchMatch(.*)',redirect:'/404'}

    ]
})

//跳转前的操作
router.beforeEach((to,formContextKey,next)=>{
    document.title = to.meta.title
    next()//必须调用才能跳转
})

export default router